#pragma once
#include <windows.h>
#include <string>
#include <clocale>
#include <cstdlib>

using std::string;

const size_t default_alloc_len = 50;
static size_t GetAllocateLen( size_t len );

class String
{
public:
					String();
					String( const String& str );
					String( const string& str );
					String( const WCHAR* str );
					String( size_t n );
					~String();
public:
	size_t			size() const;
	const WCHAR*	wc_str() const;

	String			subStr( int i, int j );

					operator WCHAR*();
					operator char*();
	String&			operator+=( String& str );
	String&			operator+=( WCHAR* str );

	String&			operator=( String& str );
	String&			operator=( WCHAR*  str );

	WCHAR&			operator[]( int i );
	const WCHAR&	operator[]( int i ) const;

	friend String  operator+( String& lstr, String& rstr );
	friend String  operator+( String& lstr, WCHAR* rstr );
	friend String  operator+( WCHAR* lstr, String& rstr );

	friend bool		operator==( String& lstr, String& rstr );
	friend bool		operator==( String& lstr, WCHAR*  rstr );
	friend bool		operator==( WCHAR*  lstr, String& rstr );

	friend bool		operator!=( String& lstr, String& rstr );
	friend bool		operator!=( String& lstr, WCHAR*  rstr );
	friend bool		operator!=( WCHAR*  lstr, String& rstr );
	
private:
	WCHAR*			wstr;
	size_t			len;
	size_t			cap;
};

String operator+( String& lstr, String& rstr );
String operator+( String& lstr, WCHAR*	 rstr );
String operator+( WCHAR* lstr, String& rstr );

bool operator==( String& lstr, String& rstr );
bool operator==( String& lstr, String& rstr );
bool operator==( WCHAR* lstr, String& rstr );